package socrates.movil;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.*;

/**
 *
 * @author
 */
public class MenuP extends Activity {
	private int codAlumno;
	@Override
	public void onCreate(Bundle savedInstanceState) {
			   
		super.onCreate(savedInstanceState);
		Bundle extras = getIntent().getExtras();
	    if(extras !=null)
		{
			codAlumno = Integer.parseInt(extras.getString("codAlumno"));
		}
        setContentView(R.layout.menup);
        
        GridView gridview = (GridView) findViewById(R.id.grvmenu);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                
            	switch (position) {
				case 0:
					onClickHorarioButton();
					break;
				case 1:
					onClickNotasButton();
					break;
				case 2:
					onClickInasistenciaButton();
					break;
				case 3:
					onClickPagosButton();
					break;
				case 4:
					onClickRolExamenesButton();
					break;
				case 5:
					onClickSalirButton();
					break;
				}
            	
            }
        });
        
		
	}
	public class ImageAdapter extends BaseAdapter {
	    private Context mContext;

	    public ImageAdapter(Context c) {
	        mContext = c;
	    }

	    public int getCount() {
	        return menuimagesIds.length;
	    }

	    public Object getItem(int position) {
	        return null;
	    }

	    public long getItemId(int position) {
	        return 0;
	    }

	    public View getView(int position, View convertView, ViewGroup parent) {
	    	View v;
			if(convertView==null){
				LayoutInflater li = getLayoutInflater();
				v = li.inflate(R.layout.itemmenup, null);
	            v.setLayoutParams(new GridView.LayoutParams(80,130));
	            v.setPadding(5, 5, 5, 5);
				TextView tv = (TextView)v.findViewById(R.id.txtmenuitem);
				tv.setText(menuTextIds[position]);
				ImageView iv = (ImageView)v.findViewById(R.id.imgmenuitem);
				iv.setImageResource(menuimagesIds[position]);
			}
			else
			{
				v = convertView;
			}
			return v;
	    	
	    }

	    private Integer[] menuimagesIds = {
	            R.drawable.icon, R.drawable.icon,
	            R.drawable.icon, R.drawable.icon, 
	            R.drawable.icon, R.drawable.icon, 
	    };
	    
	    private String[] menuTextIds = {
	            "Horario", "Notas Actuales",
	            "Inasistencias", "Pagos Pendientes", 
	            "Rol de Examenes","Salir",
	    };
	    
	}
	
	
	protected void IniciaActividad(Class<?> c){
		Intent i = new Intent(this, c);
		i.putExtra("codAlumno", String.valueOf(codAlumno));
		startActivity(i);
	}
	
	public void onClickHorarioButton() {
		IniciaActividad(Hora.class);
	}

	
	public void onClickNotasButton() {
		IniciaActividad(NotaCursos.class);
		
	}
	
	public void onClickPagosButton() {
		IniciaActividad(Pagos.class);
		
	}
	
	public void onClickRolExamenesButton() {
		IniciaActividad(RolExamenes.class);
	}
	
	public void onClickInasistenciaButton()
	{
		IniciaActividad(Inas.class);
	}
	
	public void onClickSalirButton()
	{
	MenuP.this.finish();
    startActivity(new Intent(MenuP.this, Inicio.class));
	}
}
